<template>
  <div @click="handleCloseDialog" class="modal" v-show="visible">
    <div class="modal__wrapper">
      <template v-if="visible && videoSrc">
        <video autoplay v-if="type === 'mp4'" :src="videoSrc"></video>
        <iframe v-else :src="videoSrc"></iframe>
      </template>
    </div>
  </div>
</template>

<script>
export default {
  name: 'VideoDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    type: {
      type: String,
      default: ''
    },
    videoSrc: {
      type: String,
      default: ''
    }
  },
  methods: {
    handleCloseDialog () {
      this.$emit('close')
    }
  }
}
</script>

<style lang="scss">
.modal {
  position: fixed;
  background: rgba(0, 0, 0, 0.4);
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  .modal__wrapper {
    width: 50%;
    height: 50%;
    transform: translate(-50%, -50%);
    position: absolute;
    left: 50%;
    top: 50%;
    video {
      width: 50%;
      margin: 0 auto;
    }
    iframe {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
